home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Go Sit In The Corner 1.0 / source / NMRP code / NMRP.c
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.1 KB  |  107 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        NMRP.c
  4.  
  5. Purpose:    This module handles cleaning up after a Notification
  6.             Manager note has been displayed.
  7.             
  8. Known bugs:    This code only compiles under THINK C 6.x.  I think the
  9.             syntax for assembler is slightly different under THINK C 5,
  10.             but I don't have my version 5 user manual handy to research
  11.             the problem.  There is a already-compiled version of the
  12.             NMRP resource in gsitc.<pi>.rsrc, so you don't really need
  13.             to compile this anyway.  I'll figure it out someday and fix it.
  14.  
  15.  
  16. This code was originally written by Dave Blumenthal, 12/92
  17. Modified for use in GSITC by Mark Pilgrim, 1/94
  18.  
  19.  
  20. Go Sit In The Corner -=- not you, just the cursor
  21. Copyright ©1994, Mark Pilgrim
  22.  
  23. This program is free software; you can redistribute it and/or modify
  24. it under the terms of the GNU General Public License as published by
  25. the Free Software Foundation; either version 2 of the License, or
  26. (at your option) any later version.
  27.  
  28. This program is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  31. GNU General Public License for more details.
  32.  
  33. You should have received a copy of the GNU General Public License
  34. along with this program in a file named "GNU General Public License".
  35. If not, write to the Free Software Foundation, 675 Mass Ave,
  36. Cambridge, MA 02139, USA.
  37.  
  38. \**********************************************************************/
  39.  
  40. extern long        ToolScratch : 0x09CE;
  41.  
  42. void FlushCodeCache(void) = 0xA0BD;
  43.  
  44. #define            _HwPriv            0xA198
  45. #define            _CacheFlush        0xA0BD
  46. #define            _Moof            0xA89F
  47.  
  48. pascal void main(NMRecPtr note)
  49. {
  50.     long            saveReturn;
  51.     Boolean            Caches040;
  52.     Boolean            Caches020;
  53.     
  54.     Caches040 = (GetOSTrapAddress(_HwPriv) != GetToolTrapAddress(_Moof));
  55.     Caches020 = (GetOSTrapAddress(_CacheFlush) != GetToolTrapAddress(_Moof));
  56.     
  57.     asm
  58.     {
  59.         move.l        note, a0
  60.         _NMRemove
  61.         
  62.         move.l        note, a0
  63.         move.l        OFFSET(NMRec, nmStr)(a0), a0
  64.         beq.s        @1
  65.         _DisposePtr
  66.         
  67. @1:        move.l        note, a0
  68.         _DisposePtr
  69.         
  70.         /* I don't like this - it uses low mem globals and assumes an     */
  71.         /* implicit link, not to mention that it's self-modifying code.   */
  72.         /* But, it seems to work.  Well, at least it compiles...          */
  73.         
  74.         /* ADDENDUM - this code assumes the following:                    */
  75.         /*  1) The compiler has put a LINK A6 at the start of the routine */
  76.         /*  2) The UNLK and RTS code at the end does not modify registers */
  77.         /*     D0 or A1, or ToolScratch                                   */
  78.         /*  3) _DisposeHandle does not modify register A1
  79.         /*  4) ToolScratch is not modified by any of the following traps: */
  80.         /*     _DisposeHandle, _RecoverHandle, _CacheFlush, and _HwPriv   */
  81.         
  82.         move.l        4(a6), saveReturn
  83.         move.l        #ToolScratch, a0
  84.         move.l        a0, 4(a6)
  85.         move.l        #0x2040A023, (a0)    ; movea.l    d0, a0 / _DisposeHandle
  86.         move.w        #0x4ED1, 4(a0)        ; jmp        (a1)
  87.     }
  88.     
  89.     if(Caches040)
  90.     {
  91.         FlushDataCache();
  92.         FlushInstructionCache();
  93.     }
  94.     else if(Caches020)
  95.     {
  96.         FlushCodeCache();
  97.     }
  98.     
  99.     asm
  100.     {
  101.         lea            main, a0
  102.         _RecoverHandle
  103.         move.l        a0, d0
  104.         move.l        saveReturn, a1
  105.     }
  106. }
  107.